window.onload = function(){
	loadAllMenu();		
}

//Initial variables

//菜单
var menu = new Menu();

// Show menu

function loadAllMenu(){
	var d = new dquery();
	d.getJSON("LoadAllMenu",function(result){
		menu.add(result);
		createMenu();
	})
}



function createMenu(){
	var content = document.getElementById('content');
	var dmenu = document.getElementById('dmenu');
	if(dmenu){
		content.removeChild(dmenu);
	}
	loadMenu(content);
}


function loadMenu(content){
	var tb = document.createElement("div");
	tb.setAttribute('id','dmenu');
	var index = 0;
	for(var i = 0; i < 8; i ++){
		var td = document.createElement("div");
		td.setAttribute('class','item');
		var icon = document.createElement("img");
		var name = document.createElement("p");
		name.setAttribute('class','name');
		var price = document.createElement("p");
		price.setAttribute('class','price');
		var slt = document.createElement("button");

		icon.setAttribute("src",menu.dishs[index].icon);

		var menuname = menu.dishs[index].getName();
		name.innerText=menuname;

		var	menuprice = menu.dishs[index].getPrice();
		price.innerText="Price: $"+menuprice;			

		slt.onclick = buy;
		slt.innerText="Buy";		
		slt.setAttribute('id',menu.dishs[index].getId());
		td.appendChild(icon);
		td.appendChild(name);
		td.appendChild(price);
		td.appendChild(slt);
		tb.appendChild(td);
		index++;

	}
	content.appendChild(tb);

}

function buy(){
	window.location.href="login.jsp";  
}